package survey.util;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class QuestionUtil {
	//public enum questionType{redio,checkbox,text};
	public static boolean validateQuestionFromAjax(String content) {
		List<String> ques=new ArrayList<String>();
		InputStream is;
		try {
			is = new ByteArrayInputStream(content.getBytes("UTF-8"));
			BufferedReader reader = null;
			reader = new BufferedReader(new InputStreamReader(is));
			String line = "";
			while ((line = reader.readLine()) != null) {
				if(!line.trim().equals("")){
					ques.add(line);
				}else{
					return false;
				}
			}
			is.close();
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(!containType(ques.get(0))){
			return false;
		}
		

		return true;
	}
	public static boolean containType(String type){
		if(type.equals("radio")||type.equals("checkbox")){
			return true;
		}
		return false;
	}
}
